<?php
/**
 * @link https://www.kancloud.cn/cleverstone/ymb2
 * @copyright Copyright (c) 2020 Yii Manager Software LLC
 */

/* ============ 表单控件值获取JS脚本 ============ */

use builder\helper\RegEx;

/** @var \yii\web\View $this View实例 */
/** @var array $controlItems 表单控件选项 */
?>
<script>
    /** @var lodash lodash工具对象  */
    /** @var ueEditor UE实例  */
    /** @var currentGroupField 当前表单组字段  */
    /** @var result 结果容器  */
<?php foreach ($controlItems as $field => $item): ?>
<?php switch ($item['control']): case 'text': //文本 ?>
<?php case 'textarea': //文本域 ?>
<?php case 'number': //数字 ?>
<?php case 'password': //密码 ?>
<?php case 'range': //数字范围 ?>
<?php case 'datetime': //日期类 datetime ?>
<?php case 'date': //日期类 date ?>
<?php case 'year': //日期类 year ?>
<?php case 'month': //日期类 month ?>
<?php case 'time': //日期类 time ?>
<?php case 'select_link': //下拉联动 ?>
<?php case 'radio': //单选框 ?>
<?php case 'hidden': //隐藏域 ?>
<?php case 'select': //下拉选择 ?>
<?php case 'switch': //开关 ?>
<?php case 'section': //数字区间 ?>
<?php case 'xselect': //xm-select普通下拉 ?>
<?php case 'xselect_tree': //xm-select下拉树 ?>
<?php case 'xselect_remote': //xm-select下拉远程搜索 ?>
<?php case 'xselect_cascader': //xm-select级联模式 ?>
<?php case 'dynamic_select': //xm-select动态下拉 ?>
<?php case 'file': //文件上传 ?>
<?php case 'star': //评分 ?>
<?php case 'transfer': //穿梭框 ?>
<?php case 'colorpicker': //颜色拾取 ?>
<?php case 'select_layui': //下拉选择(layui select) ?>
    result[currentGroupField]["<?= $field ?>"] = $scope.<?= $item['__scope'] ?>;
<?php break; case 'static_text': //静态文本 ?>
<?php if (!empty($item['canSubmit'])): ?>
    result[currentGroupField]["<?= $field ?>"] = $scope.<?= $item['__scope'] ?>;
<?php endif; ?>
<?php break; case 'select_table': //选择表格 ?>
    result[currentGroupField]["<?= $field ?>"] = lodash.map( $scope.<?= $item['__scope'] ?>, "<?= $item['valueField'] ?>" );
<?php break; case 'checkbox': //多选框 ?>
    result[currentGroupField]["<?= $field ?>"] = ym2.filterCheckboxValue($scope.<?= $item['__scope'] ?>);
<?php break; case 'richtext': //富文本(UEditor) ?>
    ueEditor = ue.getInstanceById("<?= $item['__id'] ?>");
    result[currentGroupField]["<?= $field ?>"] = ueEditor.getContent();
<?php break; case 'richtext_tinymce': //富文本(TinyMCE) ?>
    result[currentGroupField]["<?= $field ?>"] = tinyMCE.get("<?= $item['__id'] ?>").getContent();
<?php break; case 'tag': //动态标签 ?>
    result[currentGroupField]["<?= $field ?>"] = layui.ym2FormTag.values("<?= $item['__id'] ?>");
<?php break; case 'trigger': // 触发器 ?>
    <?= RegEx::js($this->renderPhpFile(__FILE__, ['controlItems' => $item['triggerItems']])) ?>
<?php break; case 'value_link': // 值连接 ?>
    <?= RegEx::js($this->renderPhpFile(__FILE__, ['controlItems' => $item['sourceControl']])) ?>
<?php break; case 'dynamic_control': // 动态控件 ?>
    <?= RegEx::js($this->renderPhpFile(__DIR__ . '/app.dynamic.control.get.php', ['controlOptions' => $item, 'currentField' => $field])) ?>
<?php break; endswitch; ?>
<?php endforeach; ?>
</script>
